package Demo;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

public class Dem01 {

    public List<String> getKafkaAllTopic() {
        Properties props = new Properties();
        String brokerList = null;
        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
        props.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, 30000);
        AdminClient client = AdminClient.create(props);


        List<String> list = new ArrayList<>();
        try {
            client.listTopics()
                    .listings()
                    .get(1, TimeUnit.MINUTES)
                    .forEach(topicListing -> {
                        System.out.println("currentTopic is: " + topicListing.name());
                        list.add(topicListing.name());
                    });
            return list;
        } catch (Exception e) {
            // LOGGER.error(e.getMessage(), e);
        } finally {
            client.close();
        }
        return null;
    }
}
